package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Override
    public List<CategoryDTO> queryCategoryByParentId(Long pid) {

        return CategoryDTO.convertEntityList(
                this.list(
                        new QueryWrapper<Category>()
                                .eq("parent_id", pid)
                )
        );

    }

    @Override
    public List<CategoryDTO> queryCategoryByIds(List<Long> ids) {
        return CategoryDTO.convertEntityList(
                this.listByIds(ids)
        );
    }

    @Override
    public CategoryDTO queryCategoryById(Long id) {
        return new CategoryDTO(this.getById(id));
    }


}